package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbOrderItemMapper;
import com.dongdongshop.mapper.TbOrderMapper;
import com.dongdongshop.pojo.*;
import com.dongdongshop.service.TbOrderItemService;
import com.dongdongshop.service.TbSellerService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TbOrderItemServiceImpl implements TbOrderItemService {

    @Autowired
    private TbOrderItemMapper tbOrderItemMapper;

    @Autowired
    private TbOrderMapper tbOrderMapper;

    @Reference
    private TbSellerService tbSellerService;

    @Override
    public void insert(TbOrderItem orderItem) {
        tbOrderItemMapper.insertSelective(orderItem);
    }

    @Override
    public void insertBYOTN(String tradeNo, String outTradeNo) {
        tbOrderItemMapper.insertBYOTN(tradeNo,outTradeNo);
    }

    @Override
    public List<TbOrderItem> selectOrderItem() {
        return null;
    }

    @Override
    public List<Cart> findOrderPayList(TbUser user, String status) {
        List<TbOrder> orderList = tbOrderMapper.selectByUserId(user.getUsername(),status);
        List<Cart> cartList = new ArrayList<>();
        List<TbOrderItem> orderItemList;
        for (TbOrder order : orderList) {
            Cart cart = new Cart();
//            TbSeller seller = tbSellerService.echo(order.getSellerId());
            TbSeller seller = tbSellerService.echo("1");
            cart.setSellerId(seller.getSellerId());
            cart.setSellerNikeName(seller.getNickName());
            orderItemList = tbOrderItemMapper.selectByOrderId(order.getOrderId());
            cart.setOrderItemList(orderItemList);
            cartList.add(cart);
        }
        return cartList;
    }
}
